﻿//import log
var box = {};
box.count = 0;

//打开一个远程地址的内容
box.open_url = function (title, url, attrs, is_modal, width, height) {
    $.post(url, attrs, function (html) {
        box.open(title, html, is_modal, width, height);
    });
}

box.dialog = function (title, content, attrs) {
    var box_id = box.create_box(title, content);
    $("#" + box_id).wijdialog(attrs);
}

box.open_window = function (title, url, width, height) {
    var box_id = box.create_box(title, "");
    $("#" + box_id).wijdialog({ width: width, height: height, contentUrl: url, autoOpen: true });
}

box.create_box = function (title, content) {
    box.count++;
    var box_id = "dialog_" + box.count;
    var html = "<div id='" + box_id + "' title='" + title + "'>";
    html += content;
    html += "</div>";
    $("body").append(html);
    return box_id;
}

box.open = function (title, content, is_modal, width, height) {
    width = width == null ? 500 : width;
    height = height == null ? 300 : height;
    var box_id = box.create_box(title, content);
    $("#" + box_id).wijdialog({
        autoOpen: true,
        modal: is_modal,
        width: width,
        height: height
    });
}

box.alert = function (title, content, action) {
    var box_id = box.create_box(title, content);
    $("#" + box_id).wijdialog({
        autoOpen: true,
        modal: true,
        buttons: {
            "知道了": function () {
                $(action);
                $(this).wijdialog("close");
            }
        },
        captionButtons: {
            pin: { visible: false },
            refresh: { visible: false },
            toggle: { visible: false },
            minimize: { visible: false },
            maximize: { visible: false }
        }
    });
    log.log_text(title + "：" + content, true);
}

box.error = function (content, action) {
    var box_id = box.create_box("错误", content);
    $("#" + box_id).wijdialog({
        autoOpen: true,
        modal: true,
        buttons: {
            "知道了": function () {
                $(action);
                $(this).wijdialog("close");
            }
        },
        captionButtons: {
            pin: { visible: false },
            refresh: { visible: false },
            toggle: { visible: false },
            minimize: { visible: false },
            maximize: { visible: false }
        }
    });
    log.log_text("错误：" + content, false);
}

box.confirm = function (title, content, action) {
    var box_id = box.create_box(title, content);
    $("#" + box_id).wijdialog({
        autoOpen: true,
        modal: true,
        buttons: {
            "是": function () {
                $(action);
                $(this).wijdialog("close");
            },
            "否": function () {
                $(this).wijdialog("close");
            },
            "取消": function () {
                $(this).wijdialog("close");
            }
        },
        captionButtons: {
            pin: { visible: false },
            refresh: { visible: false },
            toggle: { visible: false },
            minimize: { visible: false },
            maximize: { visible: false }
        }
    });
}

box.prompt = function (title, content, action) {
    var box_id = box.create_box(title, content + "<br/><input type='text' class='hu8-prompt-question' />");
    $("#" + box_id).wijdialog({
        autoOpen: true,
        height: 180,
        width: 400,
        modal: true,
        buttons: {
            Ok: function () {
                var value = $(action);
                $(this).wijdialog("close");
            }
        },
        captionButtons: {
            pin: { visible: false },
            refresh: { visible: false },
            toggle: { visible: false },
            minimize: { visible: false },
            maximize: { visible: false }
        }
    });
}